package Game.Windows 
{
	import flash.display.Sprite;
	import flash.text.TextField;
	/**
	 * ...
	 * @author Yevgeniy Logachev
	 */
	public class DebugWindow extends Sprite
	{
		private static const 	s_instance:DebugWindow 			= new DebugWindow();
		private var 			m_textField:TextField			= null;
				
		public function DebugWindow() 
		{
			if (s_instance == null)
			{
				trace ("World initialized");
				
				graphics.beginFill(0x118833, 0.5);
				graphics.drawRect(0, 0, Settings.screenWidth - 40, Settings.screenHeight - 40);
				
				m_textField = new TextField();
				
				m_textField.textColor = 0xFFFFFF;
				m_textField.text = "Debug Window";
				m_textField.x = 0;
				m_textField.y = 0;
				m_textField.width = Settings.screenWidth - 40;
				m_textField.height = Settings.screenHeight - 40;
				m_textField.multiline = true;
				m_textField.wordWrap = true;
				
				x = 20;
				y = 20;
	
				name = "DebugWindow"
				visible = true;
				
				addChild(m_textField);
			}
			else
			{
				trace("ERROR: Already existing instance in Singleton");
				throw new Error("Already existing instance in Singleton");
			}
		}
		
		public static function get instance():DebugWindow
		{
			return s_instance;
		}
		
		public function set show(value:Boolean):void
		{
			this.visible = value;
			if (value)
			{
				Main.mainSprite.stage.addChild(DebugWindow.instance);
			}
			else
			{
				if (Main.mainSprite.stage.getChildByName("DebugWindow") != null)
				{
					Main.mainSprite.stage.removeChild(DebugWindow.instance);
				}
			}
		}
		
		public function get show():Boolean
		{
			return visible;
		}
		
		public function addLine(text:String):void
		{
			text = m_textField.text + "\r" + text;
			m_textField.text = text;
			m_textField.scrollV = m_textField.maxScrollV;
		}
	}

}